package controllers.security;

import dto.retjson.AuthDataDto;
import play.libs.Json;
import play.mvc.Http;
import play.mvc.Result;
import utils.MVCUtils;

/**
 * User: yeqingzhou
 * Date: 12-8-30
 */
public class Secured extends play.mvc.Security.Authenticator {
    @Override
    public String getUsername(Http.Context ctx) {
        try{
            return MVCUtils.pullLocalUserKey(ctx);
        }catch (Exception e){
            return null;
        }
    }

    @Override
    public Result onUnauthorized(Http.Context ctx) {
        return ok(Json.toJson(new AuthDataDto(false, "PERMISSION_DENIED", "")));
    }
}
